package com.wdd.web.test01.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wdd.web.defaultt.entity.UserEntity;
import com.wdd.web.defaultt.mapper.UserMapperXml;
import com.wdd.web.test01.dao.UserMapperTest01;
//import com.wdd.web.test01.dao.UserMapperTest01Xml;
import com.wdd.web.test01.service.UserServiceTest01;
import com.wdd.web.test02.dao.UserMapperTest02;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;


/**
 * 整合 mybatis 默认数据源 多数据源测试
 * @author wdd_think
 *
 */
@RestController
@Api(description = "用户相关接口文档")
public class UserControllerTransactionManager {
	@Autowired
	private UserMapperTest01 userMapperTest01;//test1数据源
	@Autowired
	private UserMapperTest02 userMapperTest02;//test2数据源
	@Autowired
	private UserServiceTest01 userServiceTest01;//测试事物
//	@Autowired
//	private UserMapperTest01Xml userMapperXml;//mybatyis xml配置文件
	/**
	 * 测试test1数据源
	 * @param id
	 * @return
	 */
	@GetMapping("/getUserTest01")
	@ApiOperation(value = "测试test1数据源用户", notes = "测试test1数据源用户")
	public UserEntity getUserTest01(@ApiParam(name = "id", value = "id",required = true) @RequestParam(name = "id", required = true) String id){
		return userMapperTest01.findById(id);
	}
	/**
	 * 测试test2数据源
	 * @param id
	 * @return
	 */
	@GetMapping("/getUserTest02")
	public UserEntity getUserTest02(@ApiParam(name = "id", value = "id",required = true) @RequestParam(name = "id", required = true) String id){
		return userMapperTest02.findById(id);
	}
	/**
	 * 测试多数据源事务
	 * @param id
	 * @param name
	 * @return
	 */
	@GetMapping("/insertTest01")
	public String insertTest01(String id,String name){
		System.out.println(id+"=="+name);
		userServiceTest01.insertTest01(id,name);
		return "success";
	}
	
//    @RequestMapping("/findByXmlId")
//    public UserEntity getUser(String id) {
//    	UserEntity user=userMapperXml.findByXmlId(id);
//        return user;
//    }
	/**
	 * 测试异步注解
	 * @return
	 */
	@GetMapping("/testAsync")
	public String testAsync(){
		System.out.println("+===+1");
		userServiceTest01.testAsync();
		System.out.println("+===+3");
		return "success";
	}

}
